<script lang="ts" setup>
import { reactive, ref, watch } from 'vue';
import TableViewTabs from '../tableViewTabs/index.vue';
import IndexViewTabs from '../indexViewTabs/index.vue';

const props = defineProps({
  previewData: {
    type: Object
  },
  indexViewData: {
    type: Object
  }
});
const emit = defineEmits(['changePageNum', 'changePageSize', 'changeTableTab']);
const previewResultData = ref<any>();
const previewIndexData = ref<any>();

const activeKey = ref('0');

const changePageNum = (v: any, type: any) => {
  emit('changePageNum', v, type);
};
const changePageSize = (v: any, type: any) => {
  emit('changePageSize', v, type);
};

const handleChangeTable = (v: any) => {
  activeKey.value = v;
  emit('changeTableTab', v);
};

watch(
  () => props.previewData,
  (val) => {
    previewResultData.value = val;
    activeKey.value = '0';
  },
  {
    immediate: true
  }
);
watch(
  () => props.indexViewData,
  (val) => {
    previewIndexData.value = val;
  }
);
</script>
<template>
  <a-tabs
    :active-key="activeKey"
    class="reload-tabs"
    type="card"
    @change="handleChangeTable"
  >
    <a-tab-pane key="0" title="表视角">
      <table-view-tabs
        :table-view="previewResultData"
        @changePageNum="changePageNum"
        @changePageSize="changePageSize"
      ></table-view-tabs>
    </a-tab-pane>
    <a-tab-pane key="1" title="指标视角">
      <index-view-tabs
        :index-view="previewIndexData"
        @changePageNum="changePageNum"
        @changePageSize="changePageSize"
      ></index-view-tabs>
    </a-tab-pane>
    <a-tab-pane key="contract" title="横向对比"> </a-tab-pane>
  </a-tabs>
</template>
<style lang="scss" scoped>
.reload-tabs {
  :deep(.arco-tabs-nav-type-card) {
    &::before {
      background-color: transparent;
    }
    .arco-tabs-tab {
      width: 100px;
      height: 36px;
      padding: 0;
      background-color: #fff;
      line-height: 36px;
      border: 1px solid #d4d7e1;
      border-right: none;
      &:last-child {
        border-right: 1px solid #d4d7e1;
      }
      .arco-tabs-tab-title {
        width: 100%;
        text-align: center;
      }
    }
    .arco-tabs-tab-active {
      background: #f0f6ff;
      border: 1px solid #628cff !important;
      border-radius: 0;
    }
    .arco-tabs-tab:first-child {
      border-radius: 3px 0 0 3px;
    }
    .arco-tabs-tab:first-child.arco-tabs-tab-active + .arco-tabs-tab {
      border-left: 0;
    }
    .arco-tabs-tab:nth-child(2).arco-tabs-tab-active + .arco-tabs-tab {
      border-left: 0;
    }
    .arco-tabs-tab:last-child {
      border-radius: 0 3px 3px 0;
    }
  }
  :deep(.arco-tabs-content) {
    border: none;
  }
}
</style>